﻿package mortal.game.view.CollectExchange.cellRender
{
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;

    public class CollectExchangeItemCellRender extends GCellRenderer
    {
        public var _item:BaseItem;
        private var _itemData:ItemData;
        private var _sign:GBitmap;
        private var _signType:int;
        private var _exchangeText:GTextFiled;
        private static const _exchangeTextX:int = 39;
        private static const _singleExchangeTextLength:int = 7;

        public function CollectExchangeItemCellRender()
        {
            return;
        }// end function

        private function onLoadResCompl() : void
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._item = UICompomentPool.getUICompoment(BaseItem);
            this._item.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            this.addChild(this._item);
            this._item.isDragAble = false;
            this._item.isShowLock = false;
            this._item.isBind = false;
            this._sign = UIFactory.gBitmap("", 42, 10, this);
            this._exchangeText = UIFactory.gTextField("", _exchangeTextX, 22, 220, 20, this._item, GlobalStyle.textFormatBai);
            this._exchangeText.mouseEnabled = false;
            LoaderHelp.addResCallBack(ResFileConst.collectExchange, this.onLoadResCompl);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            super.data = param1;
            this._itemData = param1 as ItemData;
            if (this._itemData)
            {
                _loc_2 = this._itemData.serverData.itemCode;
                this._item.itemCode = _loc_2;
                this._item.amount = this._itemData.extData["num"] as int;
                this._signType = this._itemData.extData["signType"] as int;
                switch(this._signType)
                {
                    case 1:
                    {
                        this._sign.bitmapData = GlobalClass.getBitmapData(ImagesConst.collectExchangeCellLabelPlus);
                        break;
                    }
                    case 2:
                    {
                        this._sign.bitmapData = GlobalClass.getBitmapData(ImagesConst.collectExchangeCellLabelEqual);
                        break;
                    }
                    case 3:
                    {
                        this._sign.bitmapData = null;
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                _loc_3 = this._item.amount;
                _loc_4 = Cache.instance.pack.backPackCache.getItemCountByItemCode(_loc_2, true);
                this._exchangeText.x = _exchangeTextX;
                _loc_5 = _loc_4.toString().length + _loc_3.toString().length + 1;
                if (_loc_4 >= _loc_3)
                {
                    this._exchangeText.htmlText = Language.getStringByParam(90003, _loc_4, _loc_3);
                }
                else
                {
                    this._exchangeText.htmlText = Language.getStringByParam(90004, _loc_4, _loc_3);
                }
                this._exchangeText.x = this._exchangeText.x - _loc_5 * _singleExchangeTextLength;
                _loc_6 = this._itemData.extData["exchangeType"] as int;
                if (_loc_6 == 2)
                {
                    this._item.isShowLock = true;
                    this._item.isBind = true;
                    this._exchangeText.htmlText = "";
                }
                if (this._itemData.serverData.itemCode < 1000)
                {
                    this._item.toolTipData = GameDefConfig.instance.getEPrictUnitName(this._itemData.serverData.itemCode) + this._item.amount;
                }
            }
            else
            {
                this._item.itemData = null;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._item.dispose(param1);
            this._exchangeText.dispose(param1);
            this._sign.dispose(param1);
            this._item = null;
            this._itemData = null;
            this._exchangeText = null;
            this._sign = null;
            LoaderHelp.removeResEvent(ResFileConst.collectExchange, this.onLoadResCompl);
            return;
        }// end function

    }
}
